﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace book
{
    class Class1 { }
    
    class MMMMM
    {
        private Class1 c1 = new Class1();
        public void Start()
        {
            MMMMM program = new MMMMM();
            
            Stopwatch timer = new Stopwatch();
            timer.Start();
            for(int i = 0; i < 100000; i++)
            {
                program.Dosomething1();
            }
            timer.Stop();
            decimal micro = timer.Elapsed.Ticks / 10m;
            Console.WriteLine("IS运算100000次所需时间，{0:F1}微秒",micro);
 
            timer = new Stopwatch();
            timer.Start();
            for(int i = 0; i < 100000; i++)
            {
                program.Dosomething2();
            }
            timer.Stop();
            micro = timer.Elapsed.Ticks/10m;
            Console.WriteLine("AS运算100000次所需时间，{0:F1}微秒",micro);
            
            timer = new Stopwatch();
            timer.Start();
            for(int i = 0; i < 100000; i++)
            {
                program.Dosomething3();
            }
            timer.Stop();
            micro = timer.Elapsed.Ticks/10m;
            Console.WriteLine("()运算100000次所需时间，{0:F1}微秒",micro);
            
        }
        public void Dosomething1()
        {
            object c2 = c1;
            if(c2 is Class1 item)
            {
                // Class1 c = (Class1)c2;
            }
        }
        public void Dosomething2()
        {
            object c2 = c1;
            Class1 c = c2 as Class1;
            if (c != null)
            {
 
            }
        }
        
        public void Dosomething3()
        {
            object c2 = c1;
            Class1 c = (Class1)c2;
            if (c != null)
            {
 
            }
        }
    }
}